package com.group.activity.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.group.activity.entity.PuzzleListEntity;
import com.group.activity.service.PuzzleListService;
import com.group.common.utils.PageUtils;
import com.group.common.utils.R;

import javax.servlet.http.HttpSession;


/**
 * 拼团列表
 *
 * @author gxx
 * @email hongyezhaofang.com
 * @date 2021-11-13 10:36:51
 */
@RestController
@RequestMapping("activity/puzzlelist")
public class PuzzleListController {
    @Autowired
    private PuzzleListService puzzleListService;


    /*
    创建团购
     */
    @RequestMapping("/addGroupbuy")
    public R addGroupbuy(@RequestBody @Validated PuzzleListEntity puzzleListEntity,HttpSession session){
        puzzleListService.addGroupbuy(puzzleListEntity,session);
        return R.ok("创建成功");
    }

    @RequestMapping("/test")
    public void test(HttpSession session){
        Object loginUser = session.getAttribute("loginUser");
        System.out.println(loginUser);

    }
    /*
    拼团列表 查看详细接口
    */
    @RequestMapping("/groupshoplist/{groupGoodsId}")
    public R groupshoplist(@PathVariable("groupGoodsId") Integer groupGoodsId){
        //根据商品得id查询这个商品得信息
       PuzzleListEntity puzzleListEntity= puzzleListService.groupshoplist(groupGoodsId);
       //查询成功返回结果
       return R.ok("查询成功").put("data",puzzleListEntity);
    }

    /*
    获取拼团成功得信息
    */
    @RequestMapping("/groupshopsuccess")
    public R groupshopsuccess(){
       PuzzleListEntity groupshopsuccess= puzzleListService.groupshopsuccess();

       return R.ok().put("data",groupshopsuccess);
    }

    /*
    获取
     */
    @RequestMapping("/groupshopshop")
    public R groupshopshop(@RequestBody PuzzleListEntity puzzleListEntity){
        puzzleListService.groupshopshop(puzzleListEntity);
        return R.ok("成功");
    }

}
